<template>
  <div class="home-container">
    <van-nav-bar
      title="主页"
      :fixed="true"
      right-text="生成数据"
      @click-right="onClickRight"
    />

    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell v-for="item in testList" :key="item" :title="item" />
    </van-list>
  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      testList: [],
      // 所有数据是否加载完毕，如果没有更多数据了，吧finished改成true
      finished: false,
      // 是否正在加载下一页数据，如果loading为true，则不会触发load事件
      loading: false,
    };
  },
  methods: {
    onClickRight() {
      for (let index = 0; index < 10; index++) {
        this.testList.push(index);
      }
      console.log(this.testList);
    },
    onLoad() {
      //   for (let index = 0; index < 10; index++) {
      //     this.testList.push(index);
      //   }
      console.log("触发了了load事件");
    },
  },
};
</script>

<style lang="less" scoped>
.home-container {
  padding: 46px 0 50px 0;
  .van-nav-bar {
    background-color: skyblue;
  }
  /deep/ .van-nav-bar__title {
    color: white;
  }
}
</style>